<template>
  <el-dialog :title="!dataForm.id ? '新建' : '企业详情'" :close-on-click-modal="false" append-to-body :visible.sync="visible"
    lock-scroll width="700px">
    <el-row :gutter="15" class="">
      <el-form ref="elForm" :model="dataForm" :rules="rules" size="small" label-width="150px" label-position="right">
        <template v-if="!loading">
          <el-col :span="24">
            <el-form-item label="企业名称" prop="name">
              <div>{{ dataForm.name }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="企业简称" prop="abbreviation">
              <div>{{ dataForm.abbreviation }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="企业电话" prop="phoneNumber">
              <div>{{ dataForm.phoneNumber }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="企业类型" prop="type">
              <div> {{ dataForm.type | dynamicText(enterpriseTypeList) }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="所属行业" prop="industry">
              <div> {{ dataForm.industry | dynamicText(enterpriseIndustryList) }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="所在地区" prop="mapAddress">
              <div>{{ dataForm.mapAddress }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="详细地址" prop="address">
              <div>{{ dataForm.address }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="邮政编码" prop="postcode">
              <div>{{ dataForm.postcode }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="企业传真" prop="fax">
              <div>{{ dataForm.fax }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="企业网址" prop="website">
              <div>{{ dataForm.website }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="成立时间" prop="establishmentTime">
              <div>{{ dataForm.establishmentTime }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="公司logo" prop="logo">
              <div>
                <el-avatar icon="el-icon-user-solid" size="small" style="margin-right: 0.5rem;"
                  :src="getUrl(dataForm.logo)"></el-avatar>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="企业联系人" prop="contactPerson">
              <div>{{ dataForm.contactPerson }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="用户性别" prop="sex">
              <div>{{ (dataForm.sex == 0) ? "男" : (dataForm.sex == 1) ? "女" : "未知" }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="职务" prop="post">
              <div>{{ dataForm.post }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="企业联系人电话号码" prop="contactPersonPhone">
              <div>{{ dataForm.contactPersonPhone }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="企业联系人邮箱" prop="contactPersonEmail">
              <div>{{ dataForm.contactPersonEmail }}</div>
            </el-form-item>
          </el-col>
        </template>
      </el-form>
    </el-row>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false"> 取 消</el-button>
      <!-- <el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading"> 确 定</el-button> -->
    </span>
  </el-dialog>
</template>
<script>
import { getEnterpriseInfo, putEnterprise } from "@/api/enterprise/index";
import { getDicts as getDicts } from '@/api/system/dict/data'
export default {
  dicts: ["sys_normal_disable", "sys_user_sex"],
  data() {

    return {
      dataFormSubmitType: 0,
      continueBtnLoading: false,
      index: 0,
      visible: false,
      loading: false,
      btnLoading: false,
      dataForm: {},
      // 高德
      openMap: false,
      dialogMapVisible: false,
      map: "",
      longitude: 104.065837,
      latitude: 30.657349,
      markerTool: "",
      lng: "",
      lat: "",
      mapText: "",
      rules:
        {},
      enterpriseIndustryList: [],
      enterpriseTypeList: []
    }
  },
  methods: {
    clearData() {
      this.dataForm.name = ''
      this.dataForm.abbreviation = '';
      this.dataForm.phoneNumber = '';
      this.dataForm.type = '';
      this.dataForm.industry = '';
      this.dataForm.mapAddress = '';
      this.dataForm.address = '';
      this.dataForm.postcode = '';
      this.dataForm.fax = '';
      this.dataForm.website = '';
      this.dataForm.establishmentTime = '';
      this.dataForm.logo = '';
      this.dataForm.contactPerson = '';
      this.dataForm.sex = '';
      this.dataForm.post = '';
      this.dataForm.contactPersonPhone = '';
      this.dataForm.contactPersonEmail = '';
    },
    init(id) {
      this.dataForm.id = id || 0;
      this.visible = true;
      // 获取行业
      getDicts('enterprise_industry').then(res => {
        let arr = []
        for (let i = 0; i < res.data.length; i++) {
          arr.push({
            id: res.data[i].dictValue,
            fullName: res.data[i].dictLabel
          })
        }
        this.enterpriseIndustryList = arr
      })
      // 获取企业类型
      getDicts('enterprise_type').then(res => {
        let arr1 = []
        for (let i = 0; i < res.data.length; i++) {
          arr1.push({
            id: res.data[i].dictValue,
            fullName: res.data[i].dictLabel
          })
        }
        this.enterpriseTypeList = arr1
      })
      this.clearData()
      this.$nextTick(() => {
        this.$refs['elForm'].resetFields();
        if (this.dataForm.id) {
          this.loading = true
          getEnterpriseInfo(id).then(res => {
            this.dataForm = res.data
            this.loading = false
          })
        }
      });
    },
    // 表单提交
    dataFormSubmit(type) {
      this.$refs['elForm'].validate((valid) => {
        if (valid) {
          this.btnLoading = true
          putEnterprise(this.dataForm).then(res => {
            this.visible = false
            this.btnLoading = false
            this.$emit('refreshList', true)
          })
        }
      })
    },

    getUrl(url) {
      return process.env.VUE_APP_WEBSC_API + url
    },
  },
}

</script>
<style lang="scss" scoped>
#allMap {
  width: 100%;
  height: 450px;
}

.inMapSty {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 999999;
  opacity: 0.8;
  display: flex;
  height: 36px;

}
</style>
